package String1;

import java.util.Scanner;
//判断email是否合法
public class String1_2 {
    public static void main(String[] args) {
        System.out.println("请输入一个合法email");
        Scanner scanner = new Scanner(System.in);
        String email = scanner.next();
        String1_2.isEmail(email.trim());

    }
    public static void isEmail(String email) {
        if (email.indexOf("@")!=-1){
            String substring = email.substring(0,email.indexOf("@"));
            if (substring.length()==0){
                System.out.println("email非法，@前面必须有字符");
            }else{
                String substring1 = email.substring(email.indexOf("@")+1,email.length());
                if (substring1.length()!=0){
                    boolean ok=false;
                    for (int i = 0; i < substring1.length(); i++) {
                        if (substring1.charAt(i)=='.'){
                            ok=true;
                        }
                    }
                    if (ok){
                        System.out.println("恭喜你，合法email");
                    }else{
                        System.out.println("非法email，没有点");
                    }
                }else {
                    System.out.println("email非法，@后面必须有字符");
                }
            }


        }else {
            System.out.println("非法email，请输入合法的email");
        }
    }
}
